﻿/* 2014/7/3 */
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Cosmos.Media.Play
{
    /// <summary>
    /// Represents a collection of tag strings
    /// </summary>
    public class PlayTagCollection : IEnumerable<string>, ICollection<string>, IList<string>
    {
        private Collection<string> _tags;

        private IPlayEntity _entity;

        /// <summary>
        /// Initializes a new instance of PlayTagCollection class.
        /// </summary>
        protected internal PlayTagCollection(IPlayEntity entity)
        {
            _tags = new Collection<string>();

            _entity = entity;
        }

        public void Add(string tag)
        {
            _tags.Add(tag);
        }

        public void AddRange(IEnumerable<string> tags)
        {
            foreach (string aTag in tags)
            {
                _tags.Add(aTag);
            }
        }

        public void Clear()
        {
            _tags.Clear();
        }

        public bool Contains(string tag)
        {
            return _tags.Contains(tag);
        }

        public void CopyTo(string[] array, int index)
        {
            _tags.CopyTo(array, index);
        }

        public IEnumerator<string> GetEnumerator()
        {
            return _tags.GetEnumerator();
        }

        public int IndexOf(string tag)
        {
            return _tags.IndexOf(tag);
        }

        public void Insert(int index, string tag)
        {
            _tags.Insert(index, tag);
        }

        public bool Remove(string tag)
        {
            return _tags.Remove(tag);
        }

        public void RemoveAt(int index)
        {
            _tags.RemoveAt(index);
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return (IEnumerator)_tags.GetEnumerator();
        }

        public int Count
        {
            get
            {
                return _tags.Count;
            }
        }

        bool ICollection<string>.IsReadOnly
        {
            get
            {
                return ((ICollection<string>)_tags).IsReadOnly;
            }
        }

        public string this[int index]
        {
            get
            {
                return _tags[index];
            }

            set
            {
                _tags[index] = value;
            }
        }

        public IPlayEntity Entity
        {
            get
            {
                return _entity;
            }
        }

        protected Collection<string> Tags
        {
            get
            {
                return _tags;
            }

            set
            {
                _tags = value;
            }
        }
    }
}
